package com.easy.work.view.dialog;

import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;

import com.base.syslib.impl.OneChoiceImpl;
import com.easy.work.function.mall.bean.JobCommonBean;

import java.util.List;

/**
 * Created by admin on 2017/12/24.
 */

public class DialogTools {

    /**
     * 弹出框，只能选择一个
     *
     * @param context
     * @param lists    显示数据
     * @param callback 回调函数
     * @throws
     * @since 1.0.0
     */
    public static void showOneChoiceDialog(Context context, String title, final List<JobCommonBean.ItemsEntity> lists,
                                           final OneChoiceImpl callback) {

        AlertDialog.Builder builder = new AlertDialog.Builder(context);
        builder.setTitle(title);
        String[] items = new String[lists.size()];
        for (int i = 0; i < items.length; i++) {
            JobCommonBean.ItemsEntity entity = lists.get(i);
            items[i] = entity.text;
        }
        builder.setItems(items, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {

                callback.oneChoiceConfig(lists.get(which).text, which);
            }
        });

//        builder.create();

//        if (lists.size() <= 4) {
        builder.show();
//        } else {
//            WindowManager m = ((Activity) context).getWindowManager();
//            Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
//            WindowManager.LayoutParams p = ((Activity) context).getWindow().getAttributes(); // 获取对话框当前的参数值
//            p.height = (int) (d.getHeight() * 0.6); // 高度设置为屏幕的0.5
//            p.width = (int) (d.getWidth() * 0.6); // 宽度设置为屏幕的0.8
//            builder.show().getWindow().setAttributes(p);
//            builder.show();
//        }

    }


}
